package reflect;

import java.lang.reflect.Constructor;

public class ReflectDemo3 {
    public static void main(String[] args)throws Exception {
        Person person = new Person("张三", 18);
        System.out.println(person);
        Class<?> cls = Class.forName("reflect.Person");
//        Object obj = cls.newInstance();
//        System.out.println(obj);

        // 通过反射创建对象
        Constructor<?> c = cls.getConstructor(String.class);
        Object obj = c.newInstance("李四");
        System.out.println(obj);

        Constructor<?> c2 = cls.getConstructor(String.class, int.class);
        Object obj2 = c2.newInstance("王五", 20);
        System.out.println(obj2);
    }
}
